<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\ChOperationLog;
use App\CustHub\Annotation\ChPermission;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\SmartPushSchemeRequest;
use App\CustHub\Service\ChSmartPushSchemeService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;

/**
 * 智能推送
 */
#[Controller(prefix: "ch/smart/push"), ApiAuth, VerifySignature]
class SmartPushSchemeController extends BaseController
{
    #[Inject]
    protected ChSmartPushSchemeService $service;

    /**
     * 方案列表
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('list'),ChPermission('ch:smart:push:list')]
    public function list(): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getSchemeList($this->request->all()));
    }

    /**
     * 新增
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('save'),ChOperationLog]
    public function save(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->save($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 更新
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('update'),ChOperationLog]
    public function update(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->updateScheme($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 获取详情
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getInfo')]
    public function getInfo(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getInfo($request->all()));
    }

    /**
     * 暂停任务
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('pauseTask')]
    public function pauseTask(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->pauseTask($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 开启任务
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('startTask')]
    public function startTask(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->startTask($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 取消任务
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('cancelTask')]
    public function cancelTask(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->cancelTask($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 暂停子任务
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('pauseSubTask')]
    public function pauseSubTask(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->pauseSubTask($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 开启子任务
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('startSubTask')]
    public function startSubTask(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->startSubTask($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 取消子任务
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('cancelSubTask')]
    public function cancelSubTask(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->cancelSubTask($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 获取任务列表
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getTaskList')]
    public function getTaskList(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getTaskList($request->all()));
    }

    /**
     * 获取子任务列表
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getSubTaskList')]
    public function getSubTaskList(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getSubTaskList($request->all()));
    }

    /**
     * 推送目标列表
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getTargetList')]
    public function getTargetList(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getTargetList($request->all()));
    }


    /**
     * 取消推送目标
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('cancelTarget')]
    public function cancelTarget(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->cancelTarget($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 获取发送记录
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getSendRecord')]
    public function getSendRecord(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getSendRecord($request->all()));
    }

    /**
     * 获取统计列表
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getStatsList')]
    public function getStatsList(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getStatsList($request->all()));
    }

    /**
     * 获取详细数据列表
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getDetailedDataList')]
    public function getDetailedDataList(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getDetailedDataList($request->all()));
    }

    /**
     * 删除智能推送方案
     * @param SmartPushSchemeRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('delete')]
    public function delete(SmartPushSchemeRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->deleteScheme($request->all()) ? $this->success() : $this->error();
    }
}